(function (vc, vm) {

    vc.extends({
        data: {
            editProductSeckillInfo: {
                killId: '',
                productId: '',
                valueId: '',
                prodName: '',
                prodDesc: '',
                killHours: '',
                continueHours: '',
                totalCount: '',
                oneCount: '',
                killPrice: '',
                killStock: '',
                state: '',
                startTime: '',
                endTime: '',
                selectsHours:[
                    8,10,12,14,15,16,20,22
                ]
            }
        },
        _initMethod: function () {
            vc.initDate('editProductSeckillStartTime',function(_time){
                $that.editProductSeckillInfo.startTime = _time;
            });
            vc.initDate('editProductSeckillEndTime',function(_time){
                $that.editProductSeckillInfo.endTime = _time;
            })
        },
        _initEvent: function () {
            vc.on('editProductSeckill', 'openEditProductSeckillModal', function (_params) {
                $that.refreshEditProductSeckillInfo();
                $('#editProductSeckillModel').modal('show');
                vc.copyObject(_params, $that.editProductSeckillInfo);
                $that.editProductSeckillInfo.shopId = vc.getCurrentCommunity().shopId;
            });
        },
        methods: {
            editProductSeckillValidate: function () {
                return vc.validate.validate({
                    editProductSeckillInfo: $that.editProductSeckillInfo
                }, {
                    
                    'editProductSeckillInfo.prodDesc': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "秒杀产品简介不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "256",
                            errInfo: "秒杀产品简介不能超过256"
                        },
                    ],
                    'editProductSeckillInfo.killHours': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "秒杀小时不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "秒杀小时不能超过12"
                        },
                    ],
                    'editProductSeckillInfo.continueHours': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "持续小时不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "持续小时不能超过12"
                        },
                    ],
                    'editProductSeckillInfo.totalCount': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "有效期内购买次数不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "有效期内购买次数不能超过12"
                        },
                    ],
                    'editProductSeckillInfo.oneCount': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "一次购买数量不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "一次购买数量不能超过12"
                        },
                    ],
                    'editProductSeckillInfo.killPrice': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "秒杀金额不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "秒杀金额不能超过12"
                        },
                    ],
                    'editProductSeckillInfo.killStock': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "限量不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "限量不能超过12"
                        },
                    ],
                    'editProductSeckillInfo.state': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "状态不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "状态不能超过12"
                        },
                    ],
                    'editProductSeckillInfo.startTime': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "开始时间不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "开始时间不能超过12"
                        },
                    ],
                    'editProductSeckillInfo.endTime': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "结束时间'不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "结束时间'不能超过12"
                        },
                    ],
                    'editProductSeckillInfo.killId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "秒杀ID不能为空"
                        }]

                });
            },
            editProductSeckill: function () {
                if (!$that.editProductSeckillValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    '/productSeckill.updateProductSeckill',
                    JSON.stringify($that.editProductSeckillInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editProductSeckillModel').modal('hide');
                            vc.emit('productSeckillManage', 'listProductSeckill', {});
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);
                    });
            },
            refreshEditProductSeckillInfo: function () {
                $that.editProductSeckillInfo = {
                    killId: '',
                productId: '',
                valueId: '',
                prodName: '',
                prodDesc: '',
                killHours: '',
                continueHours: '',
                totalCount: '',
                oneCount: '',
                killPrice: '',
                killStock: '',
                state: '',
                startTime: '',
                endTime: '',
                selectsHours:[
                    8,10,12,14,15,16,20,22
                ]
                }
            }
        }
    });

})(window.vc, window.vc.component);
